package flc.ast.fragment;

import android.os.Bundle;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.LinearLayoutManager;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.chad.library.adapter.base.BaseQuickAdapter;

import java.util.ArrayList;
import java.util.List;

import flc.ast.R;
import flc.ast.activity.DrawActivity;
import flc.ast.activity.RecordActivity;
import flc.ast.adapter.DrawAdapter;
import flc.ast.bean.MyDrawBean;
import flc.ast.databinding.FragmentDrawBinding;
import flc.ast.utils.Content;
import stark.common.basic.base.BaseNoModelFragment;
import stark.common.basic.event.EventStatProxy;

/**
 * A simple {@link Fragment} subclass.
 * Use the {@link DrawFragment#newInstance} factory method to
 * create an instance of this fragment.
 */
public class DrawFragment extends BaseNoModelFragment<FragmentDrawBinding> {

    private DrawAdapter drawAdapter;

    @Override
    protected int onCreate() {
        return R.layout.fragment_draw;
    }

    @Override
    protected void initView() {
        EventStatProxy.getInstance().statEvent1(getActivity(), mDataBinding.event1Container);
        mDataBinding.ivRecord.setOnClickListener(this);
        mDataBinding.rvDrawList.setLayoutManager(new GridLayoutManager(mContext,2));
        drawAdapter=new DrawAdapter();
        mDataBinding.rvDrawList.setAdapter(drawAdapter);
        drawAdapter.setOnItemClickListener(this);
    }

    @Override
    protected void onClickCallback(View v) {
        switch (v.getId()){
            case R.id.ivRecord://历史记录
                RecordActivity.sFilePath= Content.MyDrawRecord;
                startActivity(RecordActivity.class);
                break;
        }
    }

    @Override
    protected void onItemClickCallback(@NonNull BaseQuickAdapter<?, ?> adapter, @NonNull View view, int position) {
        DrawActivity.type=1;
        DrawActivity.imgBg=drawAdapter.getItem(position).getDrawImg();
        startActivity(DrawActivity.class);
    }

    @Override
    protected void initData() {
        List<MyDrawBean> list=new ArrayList<>();
        list.add(new MyDrawBean(R.drawable.x1,R.drawable.b1));
        list.add(new MyDrawBean(R.drawable.x2,R.drawable.b2));
        list.add(new MyDrawBean(R.drawable.x3,R.drawable.b3));
        list.add(new MyDrawBean(R.drawable.x4,R.drawable.b4));
        list.add(new MyDrawBean(R.drawable.x5,R.drawable.b5));
        list.add(new MyDrawBean(R.drawable.x6,R.drawable.b6));
        list.add(new MyDrawBean(R.drawable.x7,R.drawable.b7));
        list.add(new MyDrawBean(R.drawable.x8,R.drawable.b8));
        drawAdapter.setList(list);
    }
}